package com.limh.base.view

import android.support.v4.view.ViewPager
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.limh.base.R
import com.limh.base.adapter.ViewPagerAdapter
import com.limh.base.router.RouterPath
import com.limh.base.utils.Logs

/**
 * @function：
 * @author： limh
 * @date： 2018/10/31
 * Copyright @2018 Corpration Name
 */
@Route(path = RouterPath.BaseMoudle.path_base_photo)
class PhotoActivity : BaseActivity() {

    private lateinit var adapter: ViewPagerAdapter
    private lateinit var images: MutableList<String>

    @Autowired
    lateinit var urls: ArrayList<String>

    override fun findView() {
        ARouter.getInstance().inject(this)
        setContentView(R.layout.base_activity_photo)
    }

    override fun initViews() {
        imgBaseClose.setOnClickListener { finish() }
    }

    override fun initDatas() {
        if (!urls.isEmpty()) {
            images = mutableListOf()
            images.addAll(urls)
            Logs.i(TAG,"$images")
            adapter = ViewPagerAdapter(context, images)
            vpBase.adapter = adapter
            txtBaseSize.text = "1/${images.size}"
            vpBase.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
                override fun onPageScrollStateChanged(state: Int) {

                }

                override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {

                }

                override fun onPageSelected(position: Int) {
                    txtBaseSize.text = "${position + 1}/${images.size}"
                }
            })
        }
    }
}